﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace ProcessFile
{
    class Program
    {
        public  static string ConvertFilestk4Ad14(string filePath)
        {

            StkFile file = new StkFile(filePath);
            string content = "";
            string[] lines = file._lines;
            int dieliectricCount = 0;
            int topLayer = file.TopLayer;
            int topSolder = file.TopSolder;
            int bottomLayer = file.BottomLayer;
            int bottomSolder = file.BottomSolder;
            int id = Common.StartIdSeq;
            string Unit = Common.GetUnit(lines);
            ConvertStk4StackupFile convertStk4StackupFile = new ConvertStk4StackupFile();
            convertStk4StackupFile.Id0 = id + 1;
            convertStk4StackupFile.Id1 = id +2;
            content += convertStk4StackupFile.Hearder;

            string subStackId = convertStk4StackupFile.SubId;
            int indexLayer = 0;
                 
            for (int i = 0; i <= Math.Max(file.BottomSolder, file.BottomLayer); i++)
            {
                string[] item = lines[i].Split('^');
                if (item.Length >= 7)
                {
                    id++;
                    if (Common.IsDielectric(item[Common.DescriptionIndex]) && i != topSolder && i != bottomSolder)
                    {
                        dieliectricCount++;
                    }
                   
                   
                    ConvertStk4StackupLayerRow convertStk4Stackup = new ConvertStk4StackupLayerRow(lines[i],indexLayer);
                    convertStk4Stackup.SubstacksID = new string[]{filePath};
                    convertStk4Stackup.Unit = Unit;
                    convertStk4Stackup.DieliectricIndex = dieliectricCount;
                    if (i == topLayer) convertStk4Stackup.IsTopLayer = true;
                    if (i == topSolder) convertStk4Stackup.IsTopSolder = true;
                    if (i == bottomLayer) convertStk4Stackup.IsBottomLayer = true;
                    if (i == bottomSolder) convertStk4Stackup.IsBottomSolder = true;
                  content+=convertStk4Stackup.ToString();
                  indexLayer++;
                }

            }
            content += convertStk4StackupFile.Footer(indexLayer+2, id);
            content = "|"+content.Replace("\r\n", "|");
            return content;
        }
    public static string  GetLayerName(string input)
    {
        string pattern = @"NAME=(?<layername>[A-z|0-9|\s]*)\|";
            Regex regex = new Regex(pattern);
        Match match = regex.Match(input);
        if (match.Success)
        {
            return match.Groups["layername"].Value;
        }
        return "";
    }
    public static string GetDielectricType(string input)
    {
        string pattern = @"DIELTYPE=(?<layertype>[A-z|0-9|\s]*)\|";
        Regex regex = new Regex(pattern);
        Match match = regex.Match(input);
        if (match.Success)
        {
            return match.Groups["layertype"].Value;
        }
        return "";
    }
    public static string GetDielectricConst(string input)
    {
        string pattern = @"DIELCONST=(?<layerconst>[A-z|0-9|\s|\.]*)\|";
        Regex regex = new Regex(pattern);
        Match match = regex.Match(input);
        if (match.Success)
        {
            return match.Groups["layerconst"].Value;
        }
        return "";
    }
    public static string GetDielectricHeight(string input)
    {
        string pattern = @"DIELHEIGHT=(?<height>[0-9|\s|\.]*)";
        Regex regex = new Regex(pattern);
        Match match = regex.Match(input);
        if (match.Success)
        {
            return match.Groups["height"].Value;
        }
        return "";
    }
    public static string GetDielectricCopThick(string input)
    {
        string pattern = @"COPTHICK=(?<height>[0-9|\s|\.]*)";
        Regex regex = new Regex(pattern);
        Match match = regex.Match(input);
        if (match.Success)
        {
            return match.Groups["height"].Value;
        }
        return "";
    }
    public static string GetDielectricMaterial(string input)
    {
        string pattern = @"DIELMATERIAL=(?<height>[A-z|0-9|\s|]*)\|";
        Regex regex = new Regex(pattern);
        Match match = regex.Match(input);
        if (match.Success)
        {
            return match.Groups["height"].Value;
        }
        return "";
    }
        public  static  void ParsingDielectricItem(string item)
        {
            
        }
        public  void SplipItemAD14(string item)
        {
            
        }
        static void Main(string[] args)
        {
            string path = @"D:\Current Project\ICD2AD14\Examples\6.stackup";
            string content = @"LAYER_V8_0LAYERID=16973832
LAYER_V8_0ID={5F2975A3-5E91-4062-A03E-2787252CD671}
LAYER_V8_0NAME=Top Paste
LAYER_V8_0USEDBYPRIMS=FALSE
LAYER_V8_0_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_0_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_0_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_0_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_0_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=1
LAYER_V8_0_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_0_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=1
LAYER_V8_0_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_1LAYERID=16973830
LAYER_V8_1ID={F5B936E2-76B8-4E25-88D0-11ACA440936D}
LAYER_V8_1NAME=Top Overlay
LAYER_V8_1USEDBYPRIMS=FALSE
LAYER_V8_1_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_1_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_1_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=0
LAYER_V8_1_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_1_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_1_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_1_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_1_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_2LAYERID=16973834
LAYER_V8_2ID={666F8FAA-D31A-4681-8CD4-DD65348A61E9}
LAYER_V8_2NAME=Top Solder
LAYER_V8_2USEDBYPRIMS=FALSE
LAYER_V8_2_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_2_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_2_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=0
LAYER_V8_2_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_2_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_2_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_2_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_2_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_2DIELTYPE=3
LAYER_V8_2DIELCONST=3.5
LAYER_V8_2DIELHEIGHT=0.4mil
LAYER_V8_2DIELMATERIAL=Solder Resist
LAYER_V8_3LAYERID=16777217
LAYER_V8_3ID={B1208237-345B-4828-8B9F-E9C026AB471E}
LAYER_V8_3NAME=Component Side
LAYER_V8_3USEDBYPRIMS=FALSE
LAYER_V8_3_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_3_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_3_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=0
LAYER_V8_3_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_3_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_3_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_3_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_3_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_3COPTHICK=1.4mil
LAYER_V8_3COMPONENTPLACEMENT=1
LAYER_V8_4LAYERID=17039361
LAYER_V8_4ID={BF7B6AE1-65E4-43E2-B7E0-3A8259C87A93}
LAYER_V8_4NAME=Dielectric 1
LAYER_V8_4USEDBYPRIMS=FALSE
LAYER_V8_4_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_4_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_4_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=0
LAYER_V8_4_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_4_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_4_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_4_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_4_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_4DIELTYPE=1
LAYER_V8_4DIELCONST=4.8
LAYER_V8_4DIELHEIGHT=12.6mil
LAYER_V8_4DIELMATERIAL=FR-4
LAYER_V8_5LAYERID=16842753
LAYER_V8_5ID={766D9F73-3B5A-4240-8F7C-81CE44E07EE5}
LAYER_V8_5NAME=Ground Plane 1 (GND)
LAYER_V8_5USEDBYPRIMS=TRUE
LAYER_V8_5_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_5_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=TRUE
LAYER_V8_5_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=0
LAYER_V8_5_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_5_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_5_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_5_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_5_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_5COPTHICK=1.417mil
LAYER_V8_5PULLBACKDISTANCE=20mil
LAYER_V8_6LAYERID=17039362
LAYER_V8_6ID={072AA945-7B78-4427-B55E-2FE589CFFCCD}
LAYER_V8_6NAME=Dielectric 3
LAYER_V8_6USEDBYPRIMS=FALSE
LAYER_V8_6_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_6_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_6_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_6_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_6_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_6_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_6_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_6_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_6DIELTYPE=2
LAYER_V8_6DIELCONST=4.2
LAYER_V8_6DIELHEIGHT=5mil
LAYER_V8_6DIELMATERIAL= 
LAYER_V8_7LAYERID=16777218
LAYER_V8_7ID={AC29F0B6-6860-4207-80AF-5F07442BA56F}
LAYER_V8_7NAME=Inner Layer 1
LAYER_V8_7USEDBYPRIMS=FALSE
LAYER_V8_7_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_7_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_7_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_7_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_7_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=1
LAYER_V8_7_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_7_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_7_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_7COPTHICK=1.417mil
LAYER_V8_7COMPONENTPLACEMENT=0
LAYER_V8_8LAYERID=17039363
LAYER_V8_8ID={F0C454FF-1383-4E16-8D30-19CA249F8E7E}
LAYER_V8_8NAME=Dielectric 6
LAYER_V8_8USEDBYPRIMS=FALSE
LAYER_V8_8_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_8_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_8_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_8_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_8_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=1
LAYER_V8_8_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_8_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_8_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_8DIELTYPE=1
LAYER_V8_8DIELCONST=4.2
LAYER_V8_8DIELHEIGHT=10mil
LAYER_V8_8DIELMATERIAL= 
LAYER_V8_9LAYERID=16777219
LAYER_V8_9ID={4FA28E22-C35F-4F73-89BA-DA04FA97113C}
LAYER_V8_9NAME=Inner Layer 2
LAYER_V8_9USEDBYPRIMS=FALSE
LAYER_V8_9_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_9_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_9_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_9_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_9_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=1
LAYER_V8_9_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_9_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_9_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_9COPTHICK=1.417mil
LAYER_V8_9COMPONENTPLACEMENT=0
LAYER_V8_10LAYERID=17039364
LAYER_V8_10ID={4302B6E7-6AD0-4C52-999D-7CEA01F62197}
LAYER_V8_10NAME=Dielectric 5
LAYER_V8_10USEDBYPRIMS=FALSE
LAYER_V8_10_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_10_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_10_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_10_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_10_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=1
LAYER_V8_10_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_10_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_10_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_10DIELTYPE=2
LAYER_V8_10DIELCONST=4.2
LAYER_V8_10DIELHEIGHT=5mil
LAYER_V8_10DIELMATERIAL= 
LAYER_V8_11LAYERID=16842754
LAYER_V8_11ID={13A27F80-990D-47F2-8149-3B7AD6834BC2}
LAYER_V8_11NAME=Power Plane (VCC)
LAYER_V8_11USEDBYPRIMS=TRUE
LAYER_V8_11_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_11_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=TRUE
LAYER_V8_11_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_11_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_11_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_11_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_11_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_11_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_11COPTHICK=1.417mil
LAYER_V8_11PULLBACKDISTANCE=20mil
LAYER_V8_12LAYERID=17039365
LAYER_V8_12ID={2AFE1207-DEFC-4C6F-8BB7-1A2FFE27C4CC}
LAYER_V8_12NAME=Dielectric 4
LAYER_V8_12USEDBYPRIMS=FALSE
LAYER_V8_12_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_12_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_12_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_12_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_12_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_12_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_12_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_12_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_12DIELTYPE=1
LAYER_V8_12DIELCONST=4.2
LAYER_V8_12DIELHEIGHT=10mil
LAYER_V8_12DIELMATERIAL= 
LAYER_V8_13LAYERID=16777220
LAYER_V8_13ID={9B2E7294-244E-44E5-8C77-81DFEE6F069B}
LAYER_V8_13NAME=Inner Layer 3
LAYER_V8_13USEDBYPRIMS=FALSE
LAYER_V8_13_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_13_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_13_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_13_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_13_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_13_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_13_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_13_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_13COPTHICK=1.417mil
LAYER_V8_13COMPONENTPLACEMENT=0
LAYER_V8_14LAYERID=17039366
LAYER_V8_14ID={42720269-92E7-4FF3-930B-FF1A98CEC889}
LAYER_V8_14NAME=Dielectric 7
LAYER_V8_14USEDBYPRIMS=FALSE
LAYER_V8_14_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_14_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_14_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_14_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_14_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_14_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_14_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_14_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_14DIELTYPE=2
LAYER_V8_14DIELCONST=4.2
LAYER_V8_14DIELHEIGHT=5mil
LAYER_V8_14DIELMATERIAL= 
LAYER_V8_15LAYERID=16842755
LAYER_V8_15ID={00F9ECBB-901C-4F8A-B09E-4D6637711A8A}
LAYER_V8_15NAME=Ground Plane 2 (GND)
LAYER_V8_15USEDBYPRIMS=TRUE
LAYER_V8_15_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_15_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=TRUE
LAYER_V8_15_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_15_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_15_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_15_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_15_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_15_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_15COPTHICK=1.417mil
LAYER_V8_15PULLBACKDISTANCE=20mil
LAYER_V8_16LAYERID=17039367
LAYER_V8_16ID={678135BC-0A6E-4F49-9058-14F265EBAFE0}
LAYER_V8_16NAME=Dielectric 8
LAYER_V8_16USEDBYPRIMS=FALSE
LAYER_V8_16_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_16_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_16_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_16_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_16_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_16_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_16_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_16_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_16DIELTYPE=1
LAYER_V8_16DIELCONST=4.2
LAYER_V8_16DIELHEIGHT=10mil
LAYER_V8_16DIELMATERIAL= 
LAYER_V8_17LAYERID=16842751
LAYER_V8_17ID={E22B17D4-4F51-4407-9807-47772CDFC1BA}
LAYER_V8_17NAME=Solder Side
LAYER_V8_17USEDBYPRIMS=FALSE
LAYER_V8_17_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_17_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_17_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_17_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_17_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_17_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_17_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_17_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_17COPTHICK=1.4mil
LAYER_V8_17COMPONENTPLACEMENT=2
LAYER_V8_18LAYERID=16973835
LAYER_V8_18ID={56FAF485-D01E-4956-A14C-2C130941F21D}
LAYER_V8_18NAME=Bottom Solder
LAYER_V8_18USEDBYPRIMS=FALSE
LAYER_V8_18_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_18_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_18_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_18_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_18_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_18_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_18_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_18_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_18DIELTYPE=3
LAYER_V8_18DIELCONST=3.5
LAYER_V8_18DIELHEIGHT=0.4mil
LAYER_V8_18DIELMATERIAL=Solder Resist
LAYER_V8_19LAYERID=16973831
LAYER_V8_19ID={29E40BDA-DC2C-40F0-8898-53C6D13AE432}
LAYER_V8_19NAME=Bottom Overlay
LAYER_V8_19USEDBYPRIMS=FALSE
LAYER_V8_19_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_19_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_19_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=0
LAYER_V8_19_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_19_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=0
LAYER_V8_19_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_19_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=0
LAYER_V8_19_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
LAYER_V8_20LAYERID=16973833
LAYER_V8_20ID={CA6A77DA-1F46-4BFA-ADE1-6625CE48ED21}
LAYER_V8_20NAME=Bottom Paste
LAYER_V8_20USEDBYPRIMS=FALSE
LAYER_V8_20_{5B3A99E3-B262-4D53-A173-75C25400F1D7}CONTEXT=0
LAYER_V8_20_{5B3A99E3-B262-4D53-A173-75C25400F1D7}USEDBYPRIMS=FALSE
LAYER_V8_20_{56441DA1-7B31-44EA-9AEA-23FD29467908}CONTEXT=1
LAYER_V8_20_{56441DA1-7B31-44EA-9AEA-23FD29467908}USEDBYPRIMS=FALSE
LAYER_V8_20_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}CONTEXT=1
LAYER_V8_20_{8D7CAA3D-B878-48F4-97D7-05B7BC9EE44F}USEDBYPRIMS=FALSE
LAYER_V8_20_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}CONTEXT=1
LAYER_V8_20_{1D4C6DEE-5995-4E71-9C32-4BD82FBF96C0}USEDBYPRIMS=FALSE
";
            int layerIndex = 2;
            while (content.IndexOf("LAYER_V8_"+layerIndex)>0)
            {
                int startIndex = content.IndexOf("LAYER_V8_" + layerIndex);
                int nextIndex = content.IndexOf("LAYER_V8_" + (layerIndex + 1));
                if (nextIndex>startIndex)
                {
                    string layerContent = content.Substring(startIndex, nextIndex - startIndex);
                    Console.WriteLine(layerContent);
                }
                else
                {
                    string layerContent = content.Substring(startIndex);
                    Console.WriteLine(layerContent);
                }
                layerIndex++;
            }
            Console.ReadLine();
            //AD14File content = new AD14File(path);
            //string[] layerItems = content.LayerItems;
            //for (int i = 1; i < layerItems.Length-1; i++)
            //{
              
            //    ConvertAD144StkRow ad144StkRow = new ConvertAD144StkRow(layerItems[i]);
            //    if (i==1)
            //    {
            //        ad144StkRow.IsTopSolder = true;
            //    }
            //    if (i==layerItems.Length-2)
            //    {
            //        ad144StkRow.IsBottomSolder = true;
            //    }
            //    Console.WriteLine(ad144StkRow.ToString());
            //}
            //foreach (string layerItem in content.LayerItems)
            //{
            //    Console.WriteLine(layerItem);
            //    Console.WriteLine("--------------");
            //}
            //string input =
            //    "LAYER_V8_6ID={5b30195c-1b8a-4b83-9246-72596dc55941}|LAYER_V8_6NAME=Dielectric2|LAYER_V8_6USEDBYPRIMS=FALSE|LAYER_V8_6_{6b71c852-3002-4128-8ea4-b94844bf0df2}CONTEXT=0|LAYER_V8_6_{6b71c852-3002-4128-8ea4-b94844bf0df2}USEDBYPRIMS=FALSE|LAYER_V8_6DIELTYPE=1|LAYER_V8_6DIELCONST=4.3|LAYER_V8_6DIELHEIGHT=5mil|LAYER_V8_6DIELMATERIAL=Dielectric|";
            //ConvertAD144StkRow ad144StkRow = new ConvertAD144StkRow(input);
            //Console.WriteLine(ad144StkRow.ToString());
            //string input = "LAYER_V8_6DIELCONST=4.3 mil|";
            //Console.WriteLine(GetLayerName(input));
            //Console.WriteLine(GetDielectricType(input));
            //Console.WriteLine(GetDielectricConst(input));
            //Console.WriteLine(GetDielectricHeight(input));
            //Console.WriteLine(GetDielectricMaterial(input));
            Console.ReadLine();
        }
    }
}
